package cn.tedu.tickets;

/**
 * @author :Colin
 * @version 创建时间: 2021/6/23 10:52
 *  * 需求：设计多线程编程模型，4个窗口共卖100张票
 *  * 本类通过继承Runnable类的方式完成多线程编程案例
 */
public class TestRunnable {
    public static void main(String[] args) {
        TicketRunnable target =new TicketRunnable();
        /*如果象意多线程的方式启动实现类业务，需要借助thread*/
        Thread t1=new Thread(target,"ha");
        Thread t2=new Thread(target,"ka");
        Thread t3=new Thread(target,"wa");
        Thread t4=new Thread(target,"ga");
        t1.start();
        t2.start();
        t3.start();
        t4.start();


    }

}
class TicketRunnable implements Runnable{
    int tickets =100;
    @Override
    public void run() {
        while(true){


            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            //thread在lang包下可以直接用，他有一个静态方法currenthread
            System.out.println(Thread.currentThread().getName()+"="+tickets--);
            if(tickets<=0) break;



        }
    }
}
